package com.gaojiabao.panghu.controller;

import com.gaojiabao.panghu.data.dto.ConditionDto;
import com.gaojiabao.panghu.data.pojo.Store;
import com.gaojiabao.panghu.service.StoreService;
import com.gaojiabao.panghu.utils.Result;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: gaojiabao
 * @Date: 2024/11/5 20:39
 */
@RestController
@RequestMapping("/store")
public class StoreController {
    @Resource
    private StoreService storeService;

    /**
     * 分页 + 条件查询门店列表
     * /store/storeList/{currentPage}/{pageSize}
     *
     * @param currentPage  当前页
     * @param pageSize     页大小
     * @param conditionDto 查询条件
     */
    @PostMapping("/storeList/{currentPage}/{pageSize}")
    public Result<?> getStorePageList(@PathVariable Integer currentPage,
                                      @PathVariable Integer pageSize,
                                      @RequestBody(required = false) ConditionDto conditionDto,
                                      @RequestParam(required = false) Integer deletedState) {
        return storeService.getStorePageList(currentPage, pageSize, conditionDto,deletedState);
    }

    /**
     * 逻辑删除门店 restful风格
     * /store/{id}
     *
     * @param id 门店id
     */
    @DeleteMapping("/{id}")
    public Result<?> deleteStoreById(@PathVariable Integer id) {
        return storeService.deleteStoreById(id);
    }

    /**
     * 新增门店
     * /store/add
     *
     * @param store 新增门店信息
     */
    @PostMapping("/add")
    public Result<?> addStore(@RequestBody Store store) {
        return storeService.addStore(store);
    }

    /**
     * 根据id获取门店信息
     * /store/{id}
     *
     * @param id 门店id
     */
    @GetMapping("/{id}")
    public Result<?> getStoreById(@PathVariable Integer id) {
        return storeService.getStoreById(id);
    }

    /**
     * 编辑门店
     * restful风格—— put -> 修改
     *
     * @param store 修改后的门店信息
     */
    @PutMapping()
    public Result<?> updateStore(@RequestBody Store store) {
        return storeService.updateStore(store);
    }
}
